#include "stdafx.h"
#include "Human.h"
#include "IAgent.h"
#include "../../EdgeGraphics/Model.h"
#include "../../EdgeContent/ContentManager.h"
#include "../../EdgeMath/IBoundingShape.h"
#include "../../EdgeMath/BoundingBox.h"
#include "../World/ChunkManager.h"
#include "../World/Chunk.h"
#include "../World/Heightmap.h"
#include "../World/Terrain.h"
Human::Human(void)
{
	// load model and textures
	model = ContentManager::GetInstance()->LoadMdl("Content/Models/sphere.mdl");
	model->SetMaterial(ContentManager::GetInstance()->LoadMaterial("Content/Textures/sand.mat"));
	model->setShaderContainer(ContentManager::GetInstance()->LoadShaderPair("AdsLightingVertexShader.cso", "AdsLightingPixelShader.cso"));

	// create collision box
	collider = new BoundingBox(position, 1.f);
}

/*virtual*/ Human::~Human(void)
{
	agent->Release();
}

/*virtual*/ void Human::setAgent(Agent* value) /*override*/
{
	value->AddRef();
	agent = value;
}

/*virtual*/ void Human::Update(float dt) /*override*/
{	
	((BoundingBox*)collider)->position = position;

	/***********************Temporary********************************/
	// apply gravity
	acceleration.y = -90.f;
	velocity.x *= 0.995f;
	velocity.z *= 0.995f;
	float currentHeight = ChunkManager::GetInstance()->getActiveChunk()->getTerrain()->getHeightmap()->GetHeightAt((unsigned int)position.x, (unsigned int)(position.z));
	if (position.y < currentHeight)
	{
		position.y = currentHeight;
		velocity.y = 0.f;
	}
	/****************************************************************/
	GameObject::Update(dt);
}

/*virtual*/ void Human::Draw(void) /*override*/
{
	GameObject::Draw();
}